class Controller {
    constructor(systemService, uiNotification, $state, $scope, $rootScope, $cookies) {
        "ngInject"
        this.notify    = uiNotification;
        this.service   = systemService;

        this.state     = $state;
        this.scope     = $scope;
        this.cookies   = $cookies;
        this.rootScope = $rootScope;
        systemService.getPostByUser().then((r) => {
            this.select    = r.data
        })
    }

    toLogin() {
        this.service.login(this.selected).then(() => {
            this.service.setCookie().then(()=> {
                this.rootScope.isLogin = true;
                this.sLoading = false;
                this.state.go('corp');
            })
        })
    }

    next ($event) {
        if ($event && $event.keyCode !== 13) return;
        this.sLoading = true;
        return this.toLogin();
    }

    checkValid (field) {
        if ( field.$pristine ) {
            field.$pristine = false;
        }
    }
}

export default Controller;